package cn.com.huzo.webapp.controller.trade;

import cn.com.huzo.model.entities.trade.SampleDevAttachedSheetPictureEntity;
import cn.com.huzo.model.entities.trade.SampleDevAttachedSheetEntity;
import cn.com.huzo.service.trade.SampleDevAttachedSheetManager;
import cn.com.huzo.service.trade.SampleDevAttachedSheetPictureManager;
import huzofw.common.web.controller.BaseFormController;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 开发样品跟单表画面控制器
 *
 * @author 吴旭
 */
@Controller
public class SampleDevAttachmentController extends BaseFormController {

    // <editor-fold defaultstate="collapsed" desc="属性">
    private final String _resourceNo_01 = "0104";
    private final String _resourceNo_02 = "0105";
    
    @Resource(name = "SampleDevAttachedSheetManager")
    private SampleDevAttachedSheetManager _manager;

    @Resource(name = "SampleDevAttachedSheetPictureManager")
    private SampleDevAttachedSheetPictureManager _managerPicture;

    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 跳转到开发样品跟单表一览画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("trade/sampleDevAttachedSheet/01/list.html")
    public ModelAndView redirectListWnd01(HttpServletRequest request) throws Exception {
        // 设置功能号
        request.setAttribute("ResourceNo", _resourceNo_01);
        // 设置角色号
        request.setAttribute("RoleNo", _resourceNo_01);

        String _showText = "规格";
        ModelAndView view = new ModelAndView();
        view.addObject("_ShowText", _showText);
        view.addObject("_Type", 1);
        view.setViewName("01_trade/sampleDevAttachedSheet_list");
        return view;
    }

    /**
     * 跳转开发样品跟单表编辑画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("trade/sampleDevAttachedSheet/01/edit.html")
    public ModelAndView redirectEditWnd01(HttpServletRequest request) throws Exception {
        // 设置功能号
        request.setAttribute("ResourceNo", _resourceNo_01);
        // 设置角色号
        request.setAttribute("RoleNo", _resourceNo_01);

        String _showText = "规格";
        ModelAndView view = new ModelAndView();
        view.addObject("_ShowText", _showText);
        view.addObject("_Type", 1);
        view.setViewName("01_trade/sampleDevAttachedSheet_edit");
        return view;
    }

    /**
     * 跳转到开发样品跟单表一览画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("trade/sampleDevAttachedSheet/02/list.html")
    public ModelAndView redirectListWnd02(HttpServletRequest request) throws Exception {
        // 设置功能号
        request.setAttribute("ResourceNo", _resourceNo_02);
        // 设置角色号
        request.setAttribute("RoleNo", _resourceNo_02);

        String _showText = "品牌";
        ModelAndView view = new ModelAndView();
        view.addObject("_ShowText", _showText);
        view.addObject("_Type", 2);
        view.setViewName("01_trade/sampleDevAttachedSheet_list");
        return view;
    }

    /**
     * 跳转开发样品跟单表编辑画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("trade/sampleDevAttachedSheet/02/edit.html")
    public ModelAndView redirectEditWnd(HttpServletRequest request) throws Exception {
        // 设置功能号
        request.setAttribute("ResourceNo", _resourceNo_02);
        // 设置角色号
        request.setAttribute("RoleNo", _resourceNo_02);

        String _showText = "品牌";
        ModelAndView view = new ModelAndView();
        view.addObject("_ShowText", _showText);
        view.addObject("_Type", 2);
        view.setViewName("01_trade/sampleDevAttachedSheet_edit");
        return view;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="主表处理部分">
    /**
     * 根据标识取得开发样品跟单表数据。
     *
     * @param key 产品标识
     * @return 开发样品跟单表数据。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "trade/sampleDevAttachedSheet/fetchByKey.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> fetchByKey(@RequestBody final Long key) throws Exception {
        Map<String, Object> rtnValue = _manager.fetchByHeaderKey(key);
        rtnValue = rtnValue == null ? new HashMap() : rtnValue;

        return rtnValue;
    }

    /**
     * 删除开发样品跟单表计划数据。
     *
     * @param instance 产品标识
     * @return 影响的行数。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "trade/sampleDevAttachedSheet/header_delete.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Integer delete(@RequestBody SampleDevAttachedSheetEntity instance) throws Exception {
        return _manager.delete(instance);
    }

    /**
     * 根据条件取得开发样品跟单表分页数据。
     * <p>
     * @param filters 检索条件
     * @return 开发样品跟单表分页数据
     * @throws Exception
     */
    @RequestMapping(value = "trade/sampleDevAttachedSheet/fetchForPage.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> fetchForPage(@RequestBody Map<String, Object> filters) throws Exception {
        return _manager.fetchForPage(filters);
    }

    /**
     * 保存开发样品跟单表数据。
     * <p>
     * @param instance 要保存的开发样品跟单表对象。
     * @return 新增记录主键.
     * @throws Exception
     */
    @RequestMapping(value = "trade/sampleDevAttachedSheet/header_save.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Long save(@RequestBody SampleDevAttachedSheetEntity instance) throws Exception {
        Long rowsAffected;

        if (instance.getHeaderId() > 0) { //编辑
            rowsAffected = (long) _manager.update(instance);
        } else {//新增
            rowsAffected = _manager.insert(instance);
        }

        return rowsAffected;
    }

    /**
     * 审核开发样品跟单表数据。
     * <p>
     * @param instance 要审核开发样品跟单表对象。
     * @return 影响行数.
     * @throws Exception
     */
    @RequestMapping(value = "trade/sampleDevAttachedSheet/check.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Integer check(@RequestBody SampleDevAttachedSheetEntity instance) throws Exception {
        return _manager.doCheck(instance);

    } 
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="图片明细处理部分">
    /**
     * 保存开发样品跟单表图片数据。
     * <p>
     * @param instance 要保存的开发样品跟单表图片对象。
     * @return 新增记录主键.
     * @throws Exception
     */
    @RequestMapping(value = "trade/sampleDevAttachedSheet/picture/save.html",
            method = RequestMethod.POST,
            produces = {"application/json"})
    public @ResponseBody
    Map<String, Object> savePicture(@RequestBody SampleDevAttachedSheetPictureEntity instance) throws Exception {
        Map<String, Object> rtnValue = new HashMap();
        rtnValue.put("PictureId", _managerPicture.insert(instance));

        return rtnValue;
    }

    /**
     * 删除开发样品跟单表图片数据。
     *
     * @param instance 开发样品跟单表图片对象
     * @return 影响的行数。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "trade/sampleDevAttachedSheet/picture/delete.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Integer deletePicture(@RequestBody SampleDevAttachedSheetPictureEntity instance) throws Exception {
        return _managerPicture.delete(instance);
    }
    // </editor-fold>
}
